class AmendRegistrationInformationController < ApplicationController

layout "common_layout"
  def amend
   # @user = User.find_all_by_account(session[:user_id])
    case session[:user_type]
      when "student"
        redirect_to(:controller =>"amend_registration_information", :action => "student_amend")
      when "teacher"
        redirect_to(:controller =>"amend_registration_information", :action => "teacher_amend")
    end
  end
  
  def student_amend
    @student = User.find_by_account(session[:account])
    
     if request.post?  
       @student.MSN = params[:student][:MSN] 
       @student.email = params[:student][:email] 
       @student.sex = params[:student][:sex] 
       @student.tel = params[:student][:tel] 
      if @student.save
         flash.now[:notice] = "Change Information Successfully!"
      else
         flash.now[:notice] = "Have not Changed Registration Information !"
      end
     end
  end
  
  def teacher_amend
    @teacher = User.find_by_account(session[:account])
    
     if request.post?  
       @teacher.MSN = params[:teacher][:MSN] 
       @teacher.email = params[:teacher][:email] 
       @teacher.tel = params[:teacher][:tel] 
      if @teacher.save
         flash.now[:notice] = "Change Information Successfully!"
      else
         flash.now[:notice] = "Have not Changed Registration Information !"
      end
    end
  end
  
  
  def result 
    
  end
  def change_password
     @user=nil
    if request.post? and params[:user][:newpassword] == params[:user][:newpassword_confirmation]
        
           @user=User.change_password(session[:account],session[:user_type],params[:user][:password],params[:user][:newpassword])
        if @user and @user.save
            flash.now[:notice] = "Change password successfully!"
          else
            flash.now[:notice] = "Have not Changed password !"
          end
    end
  end
end
